#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
void copy_file(char* src, char* dest);
int main(int argc, char** argv)
{
    copy_file(argv[1], argv[2]);
    return 0;
}

void copy_file(char* src, char* dest)
{

    unsigned char buf[1024];
    printf("copy file:%s==>%s\n", src, dest);

    //1.打开两个文件
    int fd1 = open(src, O_RDONLY);
    if (fd1 == -1)
    {
        perror("open file1 faild");
        return;
    }
    int fd2 = open(dest, O_CREAT | O_WRONLY, 0664);
    if (fd2 == -1)
    {
        perror("open file2 faild");
        return;
    }
    //2.读多少写多少
    while (1)
    {
        int r = read(fd1, buf, 1024);
        if (r <= 0)
            break;
        write(fd2, buf, r);
    }

    //3.关闭文件
    close(fd1);
    close(fd2);
}